package com.ruoyi.web.controller.counter;

import java.util.ArrayList;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Counter;
import com.ruoyi.counter.service.ICounterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工器具柜档案Controller
 *
 * @author xll
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/counter/counter")
public class CounterController extends BaseController
{
    @Autowired
    private ICounterService counterService;

    /**
     * 查询工器具柜档案列表
     */
//    @PreAuthorize("@ss.hasPermi('counter:counter:list')")
    @GetMapping("/list")
    public TableDataInfo list(Counter counter)
    {

        startPage();
        List<Counter> list = counterService.selectCounterList(counter);
//        return getDataTable(list);
        return getDataTable(list);
    }




    /**
     * 导出工器具柜档案列表
     */
    @PreAuthorize("@ss.hasPermi('counter:counter:export')")
    @Log(title = "工器具柜档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Counter counter)
    {
        List<Counter> list = counterService.selectCounterList(counter);
        ExcelUtil<Counter> util = new ExcelUtil<Counter>(Counter.class);
        return util.exportExcel(list, "工器具柜档案数据");
    }

    /**
     * 获取工器具柜档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:counter:query')")
    @GetMapping(value = "/{counterid}")
    public AjaxResult getInfo(@PathVariable("counterid") Long counterid)
    {


        return AjaxResult.success(counterService.selectCounterById(counterid));
    }




    /**
     * 新增工器具柜档案
     */
    @PreAuthorize("@ss.hasPermi('counter:counter:add')")
    @Log(title = "工器具柜档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Counter counter)
    {
        return toAjax(counterService.insertCounter(counter));
    }

    /**
     * 修改工器具柜档案
     */
    @PreAuthorize("@ss.hasPermi('counter:counter:edit')")
    @Log(title = "工器具柜档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Counter counter)
    {
        return toAjax(counterService.updateCounter(counter));
    }





    @PreAuthorize("@ss.hasPermi('counter:counter:getToolsList')")
    @GetMapping("/getToolsList")
   // @RequestMapping(value = "/{counterid}")
//    public AjaxResult getToolsList(@RequestParam("counterid") Long  counterid)
   // public AjaxResult getToolsList( @PathVariable("counterid") String counterid)
    public AjaxResult getToolsList( Counter counter)
    {
        System.out.println("11111111111111111111111111111111111111111111111111111111111");
       System.out.println(counter.getCounterid());
       return AjaxResult.success(counterService.selectToolsList(counter.getCounterid()));


    }


    @PreAuthorize("@ss.hasPermi('counter:counter:getToolsList2')")
    @GetMapping("/getToolsList2")
    //http://localhost:8082/counter/counter/getToolsList2   ｂｏｄｙ　放ｆｏｒｍ－ｄａｔａ

    public AjaxResult getToolsList2(@RequestParam("counterid") Long  counterid)
    {
        System.out.println("222222222222222222222222222222222222222222222222222" + counterid);
      //  System.out.println(counter.getCounterid());
    //    return AjaxResult.success(counterService.selectToolsList(counter.getCounterid()));
        return AjaxResult.success(counterService.selectToolsList(counterid));


    }

    //http://localhost:8082/counter/counter/getToolsList3/2  OK
    @PreAuthorize("@ss.hasPermi('counter:counter:getToolsList2')")
    @GetMapping("/getToolsList3/{counterid}")
    public AjaxResult getToolsList３(@PathVariable("counterid") Long counterid)
    {
        System.out.println("3333333333333333333333333333333" + counterid);
        return AjaxResult.success(counterService.selectToolsList(counterid));

    }


    @PreAuthorize("@ss.hasPermi('counter:counter:getToolsList')")
    @GetMapping("/getToolsList4")
    public AjaxResult getToolsList4( Counter counter)
    {
        System.out.println("444444444444444444444444444444444444444");
        System.out.println(counter.getCounterid());
        return AjaxResult.success(counterService.selectToolsList(counter.getCounterid()));

    }


    /**
     * 删除工器具柜档案
     */
    @PreAuthorize("@ss.hasPermi('counter:counter:remove')")
    @Log(title = "工器具柜档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{counterids}")
    public AjaxResult remove(@PathVariable Long[] counterids)
    {
        return toAjax(counterService.deleteCounterByIds(counterids));
    }
}
